package com.example.photography.adapter;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;

import com.example.photography.R;
import com.example.photography.view.CustomRoundAngleImageView;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PictuerAdapter extends MyBaseAdapter {
    public PictuerAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        //1 获取或创建viewHolder
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_picture, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //2 获取当前item数据
        String uri = (String) list.get(position);
        Bitmap bitmap = null;
        try {
            bitmap = BitmapFactory.decodeStream(new FileInputStream(uri));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        holder.cvPhoto.setImageBitmap(bitmap);
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.cv_photo)
        CustomRoundAngleImageView cvPhoto;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
